package es.uned.hoomgle.web.actions;

import java.util.HashMap;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.util.ValueStack;

import es.uned.hoomgle.core.services.interfaces.HomeServiceI;
import es.uned.hoomgle.hibernate.beans.interfaces.HomeI;


public class PictureResult implements Result{
	
	private byte[] picture;
	private String name;
	@Resource
	private HomeServiceI homeService;
	
		public void execute(ActionInvocation invocation) throws Exception {

			
			HttpServletResponse response = ServletActionContext.getResponse();
			HomeDetailAction homeDetailAction = (HomeDetailAction)invocation.getAction();
			
			 HomeI home = homeService.getHomeById(Integer.valueOf(homeDetailAction.getId()));

	       

			response.getOutputStream().write(home.getPicture());
			response.getOutputStream().flush();
		}

		/**
		 * @return the picture
		 */
		public byte[] getPicture() {
			return picture;
		}
		/**
		 * @param picture the picture to set
		 */
		public void setPicture(byte[] picture) {
			this.picture = picture;
		}

		/**
		 * @return the name
		 */
		public String getName() {
			return name;
		}

		/**
		 * @param name the name to set
		 */
		public void setName(String name) {
			this.name = name;
		}


		
}
